home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Sprite 1984 - 1993
/
Sprite 1984 - 1993.iso
/
src
/
cmds
/
fsdomain
/
RCS
/
fsdomain.c,v
< prev
next >
Wrap
Text File
|
1992-03-12
|
13KB
|
558 lines
head 1.5;
branch ;
access ;
symbols ;
locks ; strict;
comment @ * @;
1.5
date 92.03.12.16.36.36; author voelker; state Exp;
branches ;
next 1.4;
1.4
date 91.10.11.14.37.03; author voelker; state Exp;
branches ;
next 1.3;
1.3
date 91.10.11.14.31.36; author voelker; state Exp;
branches ;
next 1.2;
1.2
date 91.10.11.14.27.33; author voelker; state Exp;
branches ;
next 1.1;
1.1
date 91.10.07.18.11.41; author voelker; state Exp;
branches ;
next ;
desc
@reads and writes the domain prefix of unmounted disk partitions
@
1.5
log
@added options to change domain number and serverID, or
print out file system structure info in addition to
just changing the domain prefix.
@
text
@/*
* fsdomain.c --
*
* Read and possibly change the domain prefix of a file system.
*
*/
#ifndef lint
static char rcsid[] = "$Header: /sprite/src/cmds/fsdomain/RCS/fsdomain.c,v 1.4 91/10/11 14:37:03 voelker Exp Locker: voelker $";
#endif not lint
#include "sprite.h"
#include "sys/file.h"
#include "stdio.h"
#include "errno.h"
#include "disk.h"
#include "option.h"
/*
* The size is declared in <kernel/lfsSuperBlock.h>, and is 64
* bytes.
*/
#define MAX_LFS_DOMAIN_PREFIX 63
/*
* OFS_SUMMARY_PREFIX_LENGTH is defined in <kernel/ofs.h>
*/
#define MAX_OFS_DOMAIN_PREFIX OFS_SUMMARY_PREFIX_LENGTH - 1
#define INV_DOMAIN -9999
int newDomainNum = INV_DOMAIN;
int newServerID = -1;
Boolean previousCheckPoint = FALSE;
Boolean printInfo = FALSE;
char *newDomain = NULL;
Option optionArray[] = {
{OPT_DOC, "", (Address)NIL,
"fsdomain device"},
{OPT_STRING, "name", (char *)&newDomain,
"New domain name"},
{OPT_INT, "d", (Address)&newDomainNum,
"New domain number"},
{OPT_INT, "id", (Address)&newServerID,
"New server ID"},
{OPT_TRUE, "print", (Address)&printInfo,
"Print out values of file system structures."},
{OPT_TRUE, "prev", (Address)&previousCheckPoint,
"Use the previous (older) checkpoint. Useful for when the kernel\n\tand the disk get out of sync on LFS checkpoints."}
};
static int numOptions = sizeof(optionArray) / sizeof(Option);
/*
*----------------------------------------------------------------------
*
* ChangeLfsDomainPrefix
*
* Change the domain prefix of an LFS file system. If
* newDomain is NULL, the old domain prefix is printed to stdout.
*
* Results:
* None.
*
* Side effects:
* Writes the new domain prefix to the LFS file system on stream;
* Prints to stdout.
*
*----------------------------------------------------------------------
*/
void
ChangeLfsDomainPrefix(stream, labelPtr, deviceName, newDomain)
int stream;
Disk_Label *labelPtr;
char *deviceName;
char *newDomain;
{
LfsCheckPointHdr *headerPtr;
int len;
int status;
int area = -1;
Boolean writeCheckPoint = FALSE;
headerPtr = Disk_ReadLfsCheckPointHdr(stream, labelPtr, &area);
printf("Latest checkpoint is #%d", area);
if (previousCheckPoint == TRUE) {
area = (area == 0) ? 1 : 0;
printf("...using #%d instead.\n", area);
headerPtr = Disk_ReadLfsCheckPointHdr(stream, labelPtr, &area);
} else {
putchar('\n');
}
if (headerPtr == NULL || area < 0 || area > 1) {
return;
}
if (printInfo) {
LfsCheckPointTrailer *trailerPtr;
printf("LFS Checkpoint Header on %s:\n\n", deviceName);
Disk_PrintLfsCheckPointHdr(headerPtr);
printf("\nLFS Checkpoint Regions on %s:\n\n", deviceName);
Disk_ForEachCheckPointRegion(headerPtr,
Disk_PrintLfsCheckPointRegion);
printf("\nLFS Checkpoint Trailer on %s:\n\n", deviceName);
trailerPtr = Disk_LfsCheckPointTrailer(headerPtr);
Disk_PrintLfsCheckPointTrailer(trailerPtr);
return;
}
if (newDomain != NULL) {
len = strlen(newDomain);
if (len > MAX_LFS_DOMAIN_PREFIX) {
printf("The LFS limits domain prefixes to %d characters.\n",
MAX_LFS_DOMAIN_PREFIX);
printf("%s is %d characters too long.\n", newDomain,
len - MAX_LFS_DOMAIN_PREFIX);
return;
}
sprintf(headerPtr->domainPrefix, "%s", newDomain);
writeCheckPoint = TRUE;
}
if (newDomainNum != INV_DOMAIN) {
headerPtr->domainNumber = newDomainNum;
writeCheckPoint = TRUE;
}
if (newServerID > 0) {
headerPtr->serverID = newServerID;
writeCheckPoint = TRUE;
}
if (writeCheckPoint) {
status = Disk_WriteLfsCheckPointHdr(stream, headerPtr, area,
labelPtr);
if (status != 0) {
fprintf(stderr, "fsdomain: could not write LFS checkpoint ");
fprintf(stderr, "header: %s\n", deviceName);
free((Address)headerPtr);
return;
}
}
printf("%s:\t%s\n", deviceName, headerPtr->domainPrefix);
printf("Server ID:\t%d\n", headerPtr->serverID);
printf("Domain number:\t%d\n", headerPtr->domainNumber);
free((Address)headerPtr);
return;
}
/*
*----------------------------------------------------------------------
*
* ChangeOfsDomainPrefix
*
* Change the domain prefix of an OFS file system. If
* newDomain is NULL, the old domain prefix is printed to stdout.
*
* Results:
* None.
*
* Side effects:
* Writes the new domain prefix to the OFS file system on stream,
* modifying the Ofs_SummaryInfo;
* Prints to stdout.
*
*----------------------------------------------------------------------
*/
ChangeOfsDomainPrefix(stream, labelPtr, deviceName, newDomain)
int stream;
Disk_Label *labelPtr;
char *deviceName;
char *newDomain;
{
Ofs_SummaryInfo *summaryPtr;
Ofs_DomainHeader *domainPtr;
int len;
int status;
Boolean writeSummary = FALSE;
Boolean writeDomain = FALSE;
summaryPtr = Disk_ReadSummaryInfo(stream, labelPtr);
if (summaryPtr == NULL) {
printf(stderr, "fsdomain: couldn't read Ofs_SummaryInfo\n");
return;
}
domainPtr = Disk_ReadDomainHeader(stream, labelPtr);
if (domainPtr == NULL) {
printf(stderr, "fsdomain: couldn't read Ofs_DomainHeader\n");
return;
}
if (printInfo) {
printf("OFS Domain Header on %s:\n\n", deviceName);
Disk_PrintDomainHeader(domainPtr);
printf("\nOFS Summary Info on %s:\n\n", deviceName);
Disk_PrintSummaryInfo(summaryPtr);
return;
}
if (newDomain != NULL) {
len = strlen(newDomain);
if (len > MAX_OFS_DOMAIN_PREFIX) {
printf("The OFS limits domain prefixes to %d characters.\n",
MAX_OFS_DOMAIN_PREFIX);
printf("%s is %d characters too long.\n", newDomain,
len - MAX_OFS_DOMAIN_PREFIX);
free((Address)summaryPtr);
return;
}
sprintf(summaryPtr->domainPrefix, "%s", newDomain);
writeSummary = TRUE;
}
if (newDomainNum != INV_DOMAIN) {
summaryPtr->domainNumber = newDomainNum;
writeSummary = TRUE;
}
if (newServerID > 0) {
domainPtr->device.serverID = newServerID;
writeDomain = TRUE;
}
if (writeSummary) {
status = Disk_WriteSummaryInfo(stream, labelPtr, summaryPtr);
if (status != 0) {
fprintf(stderr, "fsdomain: could not write OFS summary ");
fprintf(stderr, "sector: %s\n", deviceName);
free((Address)summaryPtr);
return;
}
}
if (writeDomain) {
status = Disk_WriteDomainHeader(stream, labelPtr, domainPtr);
if (status != 0) {
fprintf(stderr, "fsdomain: could not write OFS domain ");
fprintf(stderr, "header: %s\n", deviceName);
free((Address)summaryPtr);
return;
}
}
printf("%s:\t%s\n", deviceName, summaryPtr->domainPrefix);
printf("Server ID:\t%d\n", domainPtr->device.serverID);
printf("Domain number:\t%d\n", summaryPtr->domainNumber);
free((Address)summaryPtr);
return;
}
/*
*----------------------------------------------------------------------
*
* main --
*
* Open the device stream, read and possibly change the
* domain prefix of the file system found on the stream.
*
* Results:
* None.
*
* Side effects:
* Prints to stdout.
*
*----------------------------------------------------------------------
*/
void
main(argc, argv)
int argc;
char *argv[];
{
int stream;
int fstype;
Disk_Label *labelPtr;
char *deviceName;
argc = Opt_Parse(argc, argv, optionArray, numOptions);
if (argc != 2) {
Opt_PrintUsage(argv[0], optionArray, numOptions);
exit(FAILURE);
}
deviceName = argv[1];
/*
* If there are no new values, then just report the current ones.
*/
if (newDomain == NULL && newDomainNum == INV_DOMAIN && newServerID < 0) {
stream = open(deviceName, O_RDONLY, 0);
} else {
stream = open(deviceName, O_RDWR, 0);
}
if (stream < 0) {
perror("opening device");
exit(FAILURE);
}
labelPtr = Disk_ReadLabel(stream);
if (labelPtr == NULL) {
printf("fsdomain: cannot find label on device %s. ", deviceName);
printf("Is the label\non the disk of the correct type for");
printf("the machine being used?\n");
}
fstype = Disk_HasFilesystem(stream, labelPtr);
switch (fstype) {
case DISK_HAS_OFS:
ChangeOfsDomainPrefix(stream, labelPtr, deviceName, newDomain);
break;
case DISK_HAS_LFS:
ChangeLfsDomainPrefix(stream, labelPtr, deviceName, newDomain);
break;
default:
printf("%s: no file system found.\n", deviceName);
break;
}
free((Address)labelPtr);
}
@
1.4
log
@explicitly cast arguments to free to Address so that lint
would stop complaining
@
text
@d9 1
a9 1
static char rcsid[] = "$Header: /sprite/src/cmds/fsdomain/RCS/fsdomain.c,v 1.3 91/10/11 14:31:36 voelker Exp Locker: voelker $";
d30 7
d39 11
a49 1
"fsdomain device [new domain prefix]"}
d51 1
d81 2
a82 1
int area;
d85 8
d96 14
a109 8
/*
* If the new domain name is NULL, just print out the old one.
* If it isn't NULL, try to change the domain name and report
* the change.
*/
if (newDomain == NULL) {
printf("%s: %s\n", deviceName, headerPtr->domainPrefix);
} else {
d119 11
d138 4
a141 2
printf("%s: %s\n", deviceName, newDomain);
}
d149 1
a149 1
* ChangefsDomainPrefix
d170 6
a175 3
Ofs_SummaryInfo *summaryPtr;
int len;
int status;
d179 13
d194 1
a194 8
/*
* If the new domain name is NULL, just print out the old one.
* If it isn't NULL, try to change the domain name and report
* the change.
*/
if (newDomain == NULL) {
printf("%s: %s\n", deviceName, summaryPtr->domainPrefix);
} else {
d205 11
a222 1
printf("%s: %s\n", deviceName, newDomain);
d224 12
a264 1
char *newDomain;
d267 1
a267 1
if (argc < 2 || argc > 3) {
a271 5
if (argc == 3) {
newDomain = argv[2];
} else {
newDomain = NULL;
}
d273 1
a273 1
* if newDomain is NULL, then just report the current name
d275 1
a275 1
if (newDomain == NULL) {
@
1.3
log
@forgot to change "mydisk.h" to "disk,h"
@
text
@d9 1
a9 1
static char rcsid[] = "$Header: /sprite/src/cmds/fsdomain/RCS/fsdomain.c,v 1.2 91/10/11 14:27:33 voelker Exp Locker: voelker $";
d91 1
a91 1
free(headerPtr);
d96 1
a96 1
free(headerPtr);
d146 1
a146 1
free(summaryPtr);
d154 1
a154 1
free(summaryPtr);
d159 1
a159 1
free(summaryPtr);
d233 1
a233 1
free(labelPtr);
@
1.2
log
@first version ready for release --
if no new prefix is specified, then it just reports the current
one and exits.
Does not check to see if the file system is mounted.
no command line options
@
text
@d9 1
a9 1
static char rcsid[] = "$Header: /user6/voelker/fsdomain/RCS/fsdomain.c,v 1.1 91/10/07 18:11:41 voelker Exp Locker: voelker $";
d17 1
a17 1
#include "mydisk.h"
@
1.1
log
@Initial revision
@
text
@d9 1
a9 1
static char rcsid[] = "$Header$"
d12 1
d32 1
a32 1
"fsdomain device [domain]"}
d39 1
a39 1
* ChangeLfsDoaminPrefix
d41 2
a42 3
* Prints the domain prefix, the domain number,
* the SpriteID, the start cylinder and size, and the index of
* the LFS partition found on the stream
d48 2
a49 1
* Prints to stdout.
d53 1
a53 1
int
d63 1
d65 4
a68 4
/* headerPtr = Disk_ReadLfsCheckPointHdr(stream, labelPtr);
if (headerPtr == NULL) {
return FAILURE;
} */
d83 1
a83 1
return FAILURE;
d86 2
a87 4
/*
* need area!!!
*/
/* status = Disk_WriteLfsCheckPointHdr(stream, headerPtr, 0, labelPtr); */
d92 1
a92 1
return FAILURE;
d97 1
a97 1
return SUCCESS;
d103 1
a103 1
* ChangeOfsDomainPrefix --
d105 2
a106 3
* Prints the domain prefix, the domain number,
* the SpriteID, the start cylinder and size, and the index of
* the OFS partition found on the stream.
d112 3
a114 1
* Prints to stdout.
a117 1
int
d130 1
a130 1
return FAILURE;
d132 5
d147 1
a147 1
return FAILURE;
d155 1
a155 1
return FAILURE;
d160 1
a160 1
return SUCCESS;
d201 3
d211 1
@